package org.fmi.lje.graphics.model;

import java.awt.Dimension;
import java.awt.Font;
import java.util.HashSet;
import java.util.Set;

import org.apache.batik.svggen.SVGGraphics2D;
import org.fmi.lje.modules.SvgGraphicsProvider;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;

public class Canvas extends Shape {
	
	private final SVGGraphics2D graphics;
	
	private static final Font monoFont = new Font("Monospaced", Font.PLAIN, 12);

	protected Canvas(SVGGraphics2D graphics, int height, int width) {
		super(height, width, null);
		
		this.graphics = graphics;
	}

	protected final Set<Shape> shapes = new HashSet<Shape>();
	
	public Shape createShape(int height, int width) {
		Shape shape = new Shape(height, width, this);
		
		shapes.add(shape);

		return shape;
	}

	public Shape createShape(int x, int y, int height, int width) {
		Shape shape = new Shape(x, y, height, width, this);

		shapes.add(shape);
		
		return shape;
	}
	
	public void draw() {
		for(Shape shape : shapes) {
			shape.draw();
		}
	}
	
	public Font getFont() {
		return monoFont;
	}
	
	public SVGGraphics2D getGraphics() {
		return graphics;
	}
	
	public void setSVGCanvasSize(Dimension dimension) {
		graphics.setSVGCanvasSize(dimension);
	}
	
	public SVGDocument getDocument() {
		return (SVGDocument) graphics.getDOMFactory();
	}
	
	public Element getDocumentElement() {
		return (Element) SvgGraphicsProvider.getDocumentElement(graphics);
	}
	
	public void getRoot(Element root) {
		graphics.getRoot(root);	
	}
}
